import React, { useRef, useState } from 'react'



export default () => {
    const [count, setCount] = useState(0)
    const prevCache = useRef(null) //缓存
    return (
        <div>
            current: {count}<br></br>
            now: {prevCache.current}
            <button onClick={
                () => {
                    console.log(prevCache);
                    
                    prevCache.current = count
                    setCount(x => x + 1)
                }
            }>+</button>
            <button onClick={
                () => {
                    prevCache.current = count
                    setCount(x => x - 1)
                }
            }>-</button>
        </div>
    )
}
